package eco.lamp;

import java.text.MessageFormat;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;

public class EcoLampActivity extends Activity {
	final static int REQUEST_MAIN = 0;
	Context mContext = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);

		Button btnAbout = (Button) findViewById(R.id.btnAbout);
		btnAbout.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {

				PackageManager manager = mContext.getPackageManager();
				PackageInfo info = null;
				try {
					info = manager.getPackageInfo(mContext.getPackageName(), 0);
				} catch (NameNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				String about = MessageFormat.format("{0} v.{1}", getString(R.string.app_name),
						info.versionName);

				Builder builder = new AlertDialog.Builder(EcoLampActivity.this)
						.setTitle(
								EcoLampActivity.this.getResources().getString(
										R.string.app_name)).setMessage(about);
				AlertDialog dialog = builder.setIcon(R.drawable.ic_launcher)
						.setPositiveButton(R.string.lbClose, null).show();
				WindowManager.LayoutParams lp = dialog.getWindow()
						.getAttributes();
				lp.dimAmount = 0.0f;
				dialog.getWindow().setAttributes(lp);
				dialog.getWindow().addFlags(
						WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
			}
		});

		Button btnStart = (Button) findViewById(R.id.btnStart);
		btnStart.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Intent myIntent = new Intent(view.getContext(),
						LampsListActivity.class);
				startActivityForResult(myIntent, REQUEST_MAIN);
			}
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		finish();
	}

}